package com.example.controller;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;

/**
 * @program: springboot_course
 * @description: 在Controller类上添加@Validated注解，在接口方法的每一个参数前面添加相应校验规则注解
 * @author: ChenZhiXiang
 * @create: 2019-06-11 10:14
 **/
@RestController
@Validated
public class ValidateMethodController {

    @RequestMapping(value = "/param", method = RequestMethod.GET)
    public String printValidatedParam(
            @NotBlank(message = "用户名不能为空") String name,
            @Size(min = 3, message = "ERP长度不能小于3") String erp,
            @Min(value = 22, message = "年龄不能低于22岁") int age) {

        String msg = "name=" + name + ", erp=" + erp + ", age=" + age;
        return msg;
    }
}
